﻿@{
    ViewBag.Title = "Danh sách sản phẩm";
    Layout = "~/Views/Shared/Admin/_AdminLayout.cshtml";
}
@using PagedList.Mvc;
@using PagedList;



        <div style="background: #fff; text-align: right; height: 60px; width: 100%; font-size: 12px; border: 1px solid #ccc;">
            <span style="font-size: 18px; font-weight: bold; float: left; padding-top: 17px;padding-left: 15px;">
                DANH SÁCH SẢN PHẨM 
            </span>
            <div style="text-align: right;padding-top: 17px;padding-right:10px;">
                <span>Tổng số sản phẩm: @ViewBag.Count</span>
            </div>
        </div>
        
       
        <div style="background: #f0f0f0; text-align: center; padding: 8PX; height: 20px;
                    font-size: 14px; font-weight: bold; border-bottom: 1px solid #fff;">
            <div style="float:left;width:100%;">
                 @using (Html.BeginForm("DanhSach", "AdminSanPham", FormMethod.Get))
                 {
                    <div id="search-box" style="text-align:left">
                        <input type="text" name="SearchString" class="input" value="@ViewBag.CurrentFilter" placeholder="Tên sản phẩm..."/>
                        Danh mục
                        @Html.DropDownList("IdDanhMuc", null, new { id = "DanhMuc" })
                        Thương hiệu
                        @Html.DropDownList("IdthuongHieu", "Tất cả")
                        <input type="submit" value="Tìm kiếm" class="button4" />
                    </div>
                 }
                
            </div>
           
        </div>
        <div style="float:left">
            <br />
        <a href="~/AdminSanPham/ThemMoi" class="normal blue button input">Thêm mới</a>
        <a href="~/admin" class="normal black button input">Thoát</a>
            
            @Html.Raw(ViewBag.ThongBao)
        </div>
            <br />
        <div style="float:right;width:40%;text-align:right;">
               Hiển thị 
               <select id="HienThi">
                   <option value="5" @if (ViewBag.HienThi == 10)
                                     { @:selected="selected" 
                       }>5</option>
                   <option value="10" @if (ViewBag.HienThi == 10)
                                      { @:selected="selected" 
                       }>10</option>
                   <option value="15" @if (ViewBag.HienThi == 15)
                                      { @:selected="selected" 
                       }>15</option>
                   <option value="20" @if (ViewBag.HienThi == 20)
                                      { @:selected="selected" 
                       }>20</option>
                   <option value="50" @if (ViewBag.HienThi == 50)
                                      { @:selected="selected" 
                       }>50</option>
               </select>
                 Sắp xếp
              
               <select id="SapXep">
                   <option value="0" @if (ViewBag.SapXep == 0)
                                     { @:selected="selected" 
                       }>Mặc định</option>
                   <option value="1" @if (ViewBag.SapXep == 1)
                                     { @:selected="selected" 
                       }>Giá tăng dần</option>
                   <option value="2" @if (ViewBag.SapXep == 2)
                                     { @:selected="selected" 
                       }>Giá giảm dần</option>
                   <option value="3" @if (ViewBag.SapXep == 3)
                                     { @:selected="selected" 
                       }>Tên a đến z</option>
                   <option value="4" @if (ViewBag.SapXep == 4)
                                     { @:selected="selected" 
                       }>Tên z về a</option>
               </select>
                <script>
                    $("#HienThi").change(function () {
                        var hienthi = $(this).val();
                        window.location.href = 'http://' + window.location.host + '/AdminSanPham/DanhSach/?HienThi=' + hienthi + '&SapXep=@ViewBag.SapXep' + '&currentFilter=@ViewBag.CurrentFilter' + '&IdDanhMuc=@ViewBag.DanhMuc' + '&IdThuongHieu=@ViewBag.ThuongHieu';

                    });
                    $("#SapXep").change(function () {
                        var sapxep = $(this).val();
                        window.location.href = 'http://' + window.location.host + '/AdminSanPham/DanhSach/?SapXep=' + sapxep + '&HienThi=' + @ViewBag.HienThi + '&currentFilter=@ViewBag.CurrentFilter' + '&IdDanhMuc=@ViewBag.DanhMuc'+'&IdThuongHieu=@ViewBag.ThuongHieu';

                    });
                    $("#DanhMuc").change(function () {
                        var danhmuc = $(this).val();
                        alert(danhmuc);
                    });
                </script>
            </div>
<br />
<br />
        <table cellspacing="0" rules="rows" class="rows" border="1" style="width:100%;border-collapse:collapse;">
            <tbody>
                <tr class="item_title" style="color:White;background-color:#CCCCCC;font-family:Tahoma;font-size:12px;font-weight:bold;height:30px;">
                    <th>Mã sản phẩm</th>
                    <th>Ảnh</th>
                    <th>Tên sản phẩm</th>
                    <th>Số lượng</th>
                    <th>Giá gốc</th>
                    <th>Giá khuyến mãi</th>
                    <th>Danh mục</th>
                    <th>Hiển thị</th>
                    <th></th>
                </tr>
                 @{PagedList<BabyToys.Models.SanPham> sanphams = ViewBag.onePageOfProduct;}

                 @foreach (var sanpham in sanphams)
                 {
                    <tr class="item_row" style="border-color:#F0F0F0;border-style:Solid;height:40px;">
                        <td class="item_float">@sanpham.MaSP</td>
                        <td class="item_float"></td>
                        <td class="item_float">@sanpham.TenSP</td>
                        <td class="item_float">@sanpham.SoLuong</td>
                        <td class="item_float">@sanpham.Giaban</td>
                        <td class="item_float">@sanpham.GiaKM</td>
                        <td class="item_float">@sanpham.ThuongHieu.TenThuongHieu</td>
                        <td class="item_float">
                            @{int idd = @sanpham.IdSanPham;}

                            <input id="@Html.Raw("chkHienThi" + sanpham.IdSanPham)" type="checkbox" onclick="CapNhatHienThi(@sanpham.IdSanPham)" @if (@sanpham.HienThi == true)
                                                                                                  {
                                @:checked="checked"
                            }
                                @Html.Raw(ViewBag.Xoa==true?"":"disabled=\"disabled\"")
                            />
                            <script>
                                function CapNhatHienThi(id) {
                                    var ten = '#chkHienThi' + id;
                                    var hienthi = $(ten).is(':checked') ? true : false;
                                    //alert("a:"+x+"b:"+id);
                                    var x = confirm("Bạn có chắc muốn cập nhật sản phẩm này?");
                                    if (x == true) {
                                        //var ten = '#IsActive' + id;
                                        var id = id;
                                        $.post("/AdminSanPham/CapNhatHienThi/", { "id": id, "hienthi": hienthi },
                                            function (data) {
                                                alert("Cập Nhật Thành Công");
                                            });
                                    }
                                    else {
                                        window.location.reload();
                                    }
                                }
                            </script>
                        </td>
                        <td class="td-actions">
                            <div class="hidden-phone visible-desktop action-buttons">
                                <a href="~/AdminSanPham/Sua/@sanpham.IdSanPham" class="btnXoa small blue button">Sửa</a>
                                @{int id = @sanpham.IdSanPham;
                                  string name = @sanpham.TenSP;
                                      }
                           </div>
                        </td>
                    </tr>
                 }
        </table>
        
        @Html.PagedListPager((IPagedList)ViewBag.onePageOfProduct, page => Url.Action("DanhSach", new { page, HienThi = @ViewBag.HienThi, SapXep = @ViewBag.SapXep, currentFilter = @ViewBag.CurrentFilter, IdDanhMuc = @ViewBag.DanhMuc, IdThuongHieu = @ViewBag.ThuongHieu }), PagedListRenderOptions.OnlyShowFivePagesAtATime)
  




